{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "97c79c38-38a3-40f3-ba2e-250649347d63",
   "metadata": {},
   "source": [
    "# Multimodal Parsing with Gemini 2.0 Flash\n",
    "\n",
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_cloud_services/blob/main/examples/parse/multimodal/gemini2_flash.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
    "\n",
    "This cookbook shows you how to use LlamaParse to parse any document with the multimodal capabilities of Gemini 2.0 Flash.\n",
    "\n",
    "LlamaParse allows you to plug in external, multimodal model vendors for parsing - we handle the error correction, validation, and scalability/reliability for you.\n",
    "\n",
    "Status:\n",
    "| Last Executed | Version | State      |\n",
    "|---------------|---------|------------|\n",
    "| Aug-19-2025   | 0.6.61  | Maintained |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99786cad",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install llama-cloud-services"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15e60ecf-519c-41fc-911b-765adaf8bad4",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "Download the data - we'll use a technical datasheet for a programmable logic device (Xilinx's XC9500 In-System Programmable CPLD)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d9fb0aa-74cd-476f-8161-efd9e04248bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "!wget \"https://media.digikey.com/pdf/Data%20Sheets/AMD/XC9500_CPLD_Family.pdf\" -O data/XC9500_CPLD_Family.pdf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e29a9d7-5bd9-4fb8-8ec1-4c128a748662",
   "metadata": {},
   "source": [
    "## Initialize LlamaParse\n",
    "\n",
    "Initialize LlamaParse in multimodal mode, and specify the vendor as `gemini-2.0-flash`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2e9d9cf-8189-4fcb-b34f-cde6cc0b59c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Started parsing the file under job_id a3ea83ba-7d30-461f-a8b7-52a2380c578d\n"
     ]
    }
   ],
   "source": [
    "from llama_cloud_services import LlamaParse\n",
    "\n",
    "parser = LlamaParse(\n",
    "    parse_mode=\"parse_page_with_lvm\",\n",
    "    vendor_multimodal_model_name=\"gemini-2.0-flash\",\n",
    "    # vendor_multimodal_api_key=\"fake\",\n",
    "    high_res_ocr=True,\n",
    "    adaptive_long_table=True,\n",
    "    outlined_table_extraction=True,\n",
    "    output_tables_as_HTML=True,\n",
    "    api_key=\"llx-...\",\n",
    ")\n",
    "\n",
    "result = await parser.aparse(\"./data/XC9500_CPLD_Family.pdf\")\n",
    "gemini_documents = result.get_markdown_documents(split_by_page=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96a81df0-1026-4e30-a930-f677dc31e344",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "<table>\n",
      "<thead>\n",
      "<tr>\n",
      "<th></th>\n",
      "<th>XC9536</th>\n",
      "<th>XC9572</th>\n",
      "<th>XC95108</th>\n",
      "<th>XC95144</th>\n",
      "<th>XC95216</th>\n",
      "<th>XC95288</th>\n",
      "</tr>\n",
      "</thead>\n",
      "<tbody>\n",
      "<tr>\n",
      "<td>Macrocells</td>\n",
      "<td>36</td>\n",
      "<td>72</td>\n",
      "<td>108</td>\n",
      "<td>144</td>\n",
      "<td>216</td>\n",
      "<td>288</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>Usable Gates</td>\n",
      "<td>800</td>\n",
      "<td>1,600</td>\n",
      "<td>2,400</td>\n",
      "<td>3,200</td>\n",
      "<td>4,800</td>\n",
      "<td>6,400</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>Registers</td>\n",
      "<td>36</td>\n",
      "<td>72</td>\n",
      "<td>108</td>\n",
      "<td>144</td>\n",
      "<td>216</td>\n",
      "<td>288</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>TPD (ns)</td>\n",
      "<td>5</td>\n",
      "<td>7.5</td>\n",
      "<td>7.5</td>\n",
      "<td>7.5</td>\n",
      "<td>10</td>\n",
      "<td>15</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>Tsu (ns)</td>\n",
      "<td>3.5</td>\n",
      "<td>4.5</td>\n",
      "<td>4.5</td>\n",
      "<td>4.5</td>\n",
      "<td>6.0</td>\n",
      "<td>8.0</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>Tco (ns)</td>\n",
      "<td>4.0</td>\n",
      "<td>4.5</td>\n",
      "<td>4.5</td>\n",
      "<td>4.5</td>\n",
      "<td>6.0</td>\n",
      "<td>8.0</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>fCNT (MHz)(1)</td>\n",
      "<td>100</td>\n",
      "<td>125</td>\n",
      "<td>125</td>\n",
      "<td>125</td>\n",
      "<td>111.1</td>\n",
      "<td>92.2</td>\n",
      "</tr>\n",
      "<tr>\n",
      "<td>fSYSTEM (MHZ)(2)</td>\n",
      "<td>100</td>\n",
      "<td>83.3</td>\n",
      "<td>83.3</td>\n",
      "<td>83.3</td>\n",
      "<td>66.7</td>\n",
      "<td>56.6</td>\n",
      "</tr>\n",
      "</tbody>\n",
      "</table>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(gemini_documents[0].text)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
